
let uu = document.querySelector("#info1")
let uu1 = document.querySelector(".page")
let uuLeft = document.querySelector(".prev")
let uuRight = document.querySelector(".next")
let totalCount = 0;
let pageid = 0;

function Ajax1(api) {
    fetch(api)
        .then(body => body.json())
        .then(res => {
            let totalCount = res.totalCount / 10
            let html1 = ""
            let html = ""
            res.result.forEach(item => {
                html += `
        <li>
        <a href="./discount.html?productid=${item.productId}" productId="${item.productId}" class="clearfix">
        <div class="img fl">
        ${item.productImg2}
        </div>
        <div class="infoR">
        <div class="title">
        <h4>${item.productName}</h4>
        </div>
        <div class="other">
        <span class="mall fl">${item.productFrom} | ${item.productTime}</span>
        <i class="iconfont icon-xiaoxi fr">${item.productComCount}</i>
        </div>
        </div>
        </a>
        </li>
        `;
            })
            uu.innerHTML = html
            for (var i = 0; i < Math.ceil(totalCount); i++) {
                let num = i + 1
                html1 += `
                <option value="${num}">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    ${num}/${Math.ceil(totalCount)}
                </option>    
                `
            }
            uu1.innerHTML = html1
        })
    return uu.innerHTML
}
Ajax1("http://chst.vip:1234/api/getmoneyctrl?pageid=0")


uu1.onclick = function () {
    pageid = number.value - 1
    $.ajax({
        url: "http://chst.vip:1234/api/getmoneyctrl",
        data: {
            pageid
        }
    }).then(res => {
        let html = ""
        let totalCount = res.totalCount / 10
        if (pageid === 0) {
            uuLeft.disabled = "disabled"
            uuLeft.style.color = "rgb(204, 204, 204)"
        } else if (pageid < 0) {
            return
        }
        if (pageid < Math.ceil(totalCount) - 1) {
            uuRight.disabled = false
            uuRight.style.color = "rgb(51, 51, 51)"
        }
        if (pageid === Math.ceil(totalCount) - 1) {
            uuRight.disabled = "disabled"
            uuRight.style.color = "rgb(204, 204, 204)"
        } else if (pageid > Math.ceil(totalCount) - 1) {
            return
        }
        if (pageid > 0) {
            uuLeft.disabled = false
            uuLeft.style.color = "rgb(51, 51, 51)"
        }
        res.result.forEach(item => {
            html += `
            <li>
        <a href="./discount.html?productid=${item.productId}" productId="${item.productId}" class="clearfix">
        <div class="img fl">
        ${item.productImg2}
        </div>
        <div class="infoR">
        <div class="title">
        <h4>${item.productName}</h4>
        </div>
        <div class="other">
        <span class="mall fl">${item.productFrom} | ${item.productTime}</span>
        <i class="iconfont icon-xiaoxi fr">${item.productComCount}</i>
        </div>
        </div>
        </a>
        </li>
            `
        })
        uu.innerHTML = html
    })
}

uuRight.onclick = function () {
    pageid++
    $.ajax({
        url: "http://chst.vip:1234/api/getmoneyctrl",
        data: {
            pageid
        }
    }).then(res => {
        let html = ""
        let totalCount = res.totalCount / 10
        if (pageid === Math.ceil(totalCount) - 1) {
            uuRight.disabled = "disabled"
            uuRight.style.color = "rgb(204, 204, 204)"
        } else if (pageid > Math.ceil(totalCount) - 1) {
            return
        }
        // console.log(pageid);
        if (pageid > 0) {
            uuLeft.disabled = false
            uuLeft.style.color = "rgb(51, 51, 51)"
        }
        res.result.forEach(item => {
            html += `
                <li>
                <a href="./discount.html?productid=${item.productId}" productId="${item.productId}" class="clearfix">
                <div class="img fl">
                ${item.productImg2}
                </div>
                <div class="infoR">
                <div class="title">
                <h4>${item.productName}</h4>
                </div>
                <div class="other">
                <span class="mall fl">${item.productFrom} | ${item.productTime}</span>
                <i class="iconfont icon-xiaoxi fr">${item.productComCount}</i>
                </div>
                </div>
                </a>
                </li>
            `
        })
        uu.innerHTML = html

        //绑定option 联动
        $('.page').find('option:nth-child(' + (pageid + 1) + ')').prop('selected', true).siblings('option').prop('selected', false);
    })
}
uuLeft.onclick = function () {
    pageid--
    $.ajax({
        url: "http://chst.vip:1234/api/getmoneyctrl",
        data: {
            pageid
        }
    }).then(res => {
        let html = ""
        let totalCount = res.totalCount / 10
        if (pageid === 0) {
            uuLeft.disabled = "disabled"
            uuLeft.style.color = "rgb(204, 204, 204)"
        } else if (pageid < 0) {
            return
        }
        if (pageid < Math.ceil(totalCount) - 1) {
            uuRight.disabled = false
            uuRight.style.color = "rgb(51, 51, 51)"
        }
        res.result.forEach(item => {
            html += `
                <li>
                <a href="./discount.html?productid=${item.productId}" productId="${item.productId}" class="clearfix">
                <div class="img fl">
                ${item.productImg2}
                </div>
                <div class="infoR">
                <div class="title">
                <h4>${item.productName}</h4>
                </div>
                <div class="other">
                <span class="mall fl">${item.productFrom} | ${item.productTime}</span>
                <i class="iconfont icon-xiaoxi fr">${item.productComCount}</i>
                </div>
                </div>
                </a>
                </li>
        `
        })
        uu.innerHTML = html
        $('.page').find('option:nth-child(' + (pageid + 1) + ')').prop('selected', true).siblings('option').prop('selected', false);
    })
}


